import React from 'react';
import { connect } from 'dva'

class UserPage extends React.Component {
    render() {
        console.log(this.props.list, '用户列表');
        return (
            <div className="container">
                <h1>user</h1>
                <hr />
                <table className="table table-hover table-bordered">
                    <thead>
                        <tr className="info">
                            <td>ID</td>
                            <td>姓名</td>
                            <td>性别</td>
                            <td>年龄</td>
                            <td>城市</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody>
                        {this.props.list.map(item => {
                            return <tr key={item.id}>
                                <td>{item.id}</td>
                                <td>{item.name}</td>
                                <td>{item.sex===true?'男':'女'}</td>
                                <td>{item.age}</td>
                                <td>{item.address}</td>
                                <td>
                                    <button className="btn btn-primary btn-sm">删除</button>
                                </td>
                            </tr>
                        })}
                    </tbody>
                </table>
            </div>
        )
    }

    componentWillMount() {
        this.props.dispatch({ type: 'user/getListAsync' });
    }
}

UserPage.propTypes = {

}
const mapStateToProps = (state) => {
    return {
        list: state.user.list
    }
}
export default connect(mapStateToProps)(UserPage);